/**
 * 获取学生总人数
 */
async function getNum() {
    let snum = 0;
    const result = await axios({
        method: 'get',
        url: '/countStudent'
    });
    snum = result.data[0].num;
    let male = Math.ceil(snum / 2);
    let female =Math.floor(snum / 2);
    let totalNum = echarts.init(document.getElementById('totalNum'));
    // 指定图表的配置项和数据
    let option = {
        title: {
            text: '学生数量统计',
        },
        tooltip: {},
        legend: {
            data: ['数量']
        },
        xAxis: {
            data: ["人数","男","女"]
        },
        yAxis: {},
        series: [{
            name: '数量',
            type: 'bar',
            data: [snum, male, female]
        }]
    };
    // 使用刚指定的配置项和数据显示图表。
    totalNum.setOption(option);
}

getNum();

async function getScore(){
    let chineseNum,mathNum,englishNum;
    chineseNum = await axios({
        method:'post',
        url:'/getScoreNum',
        data:{
            cid:2
        }
    });
    chineseNum = chineseNum.data[0].num;

    mathNum = await axios({
        method:'post',
        url:'/getScoreNum',
        data:{
            cid:1
        }
    });
    mathNum = mathNum.data[0].num;

    englishNum = await axios({
        method:'post',
        url:'/getScoreNum',
        data:{
            cid:3
        }
    });
    englishNum = englishNum.data[0].num;

    let scoreTable = echarts.init(document.getElementById('scoreTable'));

    let option = {
        title: {
            text: '统计成绩及格人数',
            subtext: '纯属虚构',
            left: 'center'
        },
        tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
            orient: 'vertical',
            left: 'left',
            data: ['数学', '语文', '英语']
        },
        series: [
            {
                name: '及格人数',
                type: 'pie',
                radius: '55%',
                center: ['50%', '60%'],
                data: [
                    {value: mathNum, name: '数学'},
                    {value: chineseNum, name: '语文'},
                    {value: englishNum, name: '英语'},
                ],
                emphasis: {
                    itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    };
    scoreTable.setOption(option);
}

getScore();